Ext.define('HIT.controller.ErrorDetail', {
    extend: 'Ext.app.Controller',
    
    models : [ 'ErrorDetail' ],
	stores : [ 'ErrorDetail'] ,
    views  : ['ErrorDetailGrid','ImportFilePanel','ImportPlanPanel','ImportDBPanel'],
    onButtonClick: function(button, e, options) {
    	var p;  
    	if(button.id=='export-error'){
    		var tabPanel = Ext.getCmp('tab-error-detail');
      
    		//var a =  tabPanel.activeTab;
        	var store = tabPanel.getStore();
        	if(store.getCount()==0){
        		Share.ShowMessage("I0029");
        		return;
        	}
    		
            var import_code = store.getAt(0).get("import_code");

        	var url = '';
        	
        	if(import_code!=''){
        		url +='/'+import_code; 
        	}else{
        		url+='/null';
        	}
        	window.location.href = ctx + '/io/search/errordetail/download'+url+'/download';
    	}
    	
        if(button.id=='error-account-add'){
        	var check =  Share.checkFun(); 
        	if(check){
        	var grid=Ext.getCmp('tab-error-detail');        
          if (grid == undefined) {
			return;
		}
        var selModel = grid.getSelectionModel();
        if (selModel.hasSelection()) {
            if (selModel.getCount() != 1) {
            	Share.ShowMessage("I0009","编辑");
                return;
            }        
        	p = Share.createPanelByAlias('widget.setaccountaddpanel');
        	Share.showPanelAsWindow(p);
         }else{
        	    Share.ShowMessage("I0011","需要操作的行");
				return;
           }
        }else{
        	Share.ShowMessage("I0021");
        	//Ext.MessageBox.alert(Share.T('错误'),Share.T('无权操作，请联系主数据套所有人!'));
    		return;
        }
       }
        else if(button.id=='error-tcode-add'){ 
        	var check =  Share.checkFun(); 
        	if(check){
        	var grid=Ext.getCmp('tab-error-detail');        
            if (grid == undefined) {
    			return;
    		}
            var selModel = grid.getSelectionModel();
            if (selModel.hasSelection()) {
                if (selModel.getCount() != 1) {
                	Share.ShowMessage("I0009","编辑");
                    return;
                }
            var model = selModel.getSelection()[0];
            if(model!=undefined){    
            	p = Share.createPanelByAlias('widget.settcodeaddpanel');
            	Ext.getCmp('tcodeid').select(model.get('tcode').toString());           	
            	Ext.getCmp('beginCode').setValue(model.get('stcode'));
            	Share.showPanelAsWindow(p);
            }
        	
        }else{
        	Share.ShowMessage("I0011","需要操作的行");
			return;
       }
       }else{
    	   Share.ShowMessage("I0021");
        	//Ext.MessageBox.alert(Share.T('错误'),Share.T('无权操作，请联系主数据套所有人!'));
   		   return;
       }
      }
        else if(button.id=='error-mapping-add'){
        	var check =  Share.checkFun(); 
        	if(check){
        	var grid=Ext.getCmp('tab-error-detail');        
          if (grid == undefined) {
			return;
		}
        var selModel = grid.getSelectionModel();
        if (selModel.hasSelection()) {
            if (selModel.getCount() != 1) {
            	Share.ShowMessage("I0009","编辑");
                return;
            } 
            var model = selModel.getSelection()[0];
            if(model!=undefined){
        	p = Share.createPanelByAlias('widget.setmappingaddpanel');
        	Ext.getCmp('erpcode').setValue(model.get('param_account'));
        	Share.showPanelAsWindow(p);
          }
         }else{
        	 Share.ShowMessage("I0011","需要操作的行"); 
		     return;
           }
        }else{
        	Share.ShowMessage("I0021");
        	//Ext.MessageBox.alert(Share.T('错误'),Share.T('无权操作，请联系主数据套所有人!'));
    		return;
        }
        }
    },
    	
    init: function(application) {   	
        this.control({
            "#headpanel button": {
                click: this.onButtonClick
           }
        });
    }
    });